import { PageConfig } from 'next';
import anylogger from 'anylogger';
import '@mmstudio/an000042';
import an48 from '@mmstudio/an000048';
import an49 from '@mmstudio/an000049';
import { tbdetailsofachievements, tbtrem } from '../../../../atoms/db';
import getuser from '../../../../atoms/getuser';

const logger = anylogger('pages/api/zllweapp/gradequery/s001.api');

export type Result = {
	ok: true;

} | {
	ok: false;
	message: string;
};

export type Message = {
	select: string;
}

/**
 * pages/api/zllweapp/gradequery/s001.api
 */
const handler = an48<Result>();

handler.post(async (req, res) => {
	try {
		logger.debug('msg body:', req.body);
		const { select } = req.body as Message;

		//**获取学生id信息 */
		const db = an49();

		const user = await getuser(req);
		const student_id = '201942908581';
		//**获取学生成绩信息 */
		const data = await tbdetailsofachievements().select({
			peacetimescores: 'detailsofachievements.peacetimescores',
			percentageofresultsinpeacetime:
				'detailsofachievements.percentageofresultsinpeacetime',
			examinationscores: 'detailsofachievements.examinationscores',
			percentageofexaminationscores: 'detailsofachievements.percentageofexaminationscores',
			otherscores: 'detailsofachievements.otherscores',
			otherachievementsaccountfortheproportion: 'detailsofachievements.otherachievementsaccountfortheproportion',
			coursename: 'curriculum.coursename'
		}).leftJoin('curriculum', 'curriculum.curriculum_id', 'detailsofachievements.curriculum_id'
		).where({
			'detailsofachievements.student_id': student_id

		});

		logger.debug('data::', data);

		res.status(200).json({ ok: true, });
	} catch (error) {
		logger.trace(error);
		res.status(200).json({ ok: false, message: (error as Error).message });
	}
});

export const config = {} as PageConfig;

export default handler;
